import java.util.Random;
import java.util.Scanner;

public class Main {
    public static int[] arr;
    public static int sum1;
    public static int sum2;

    public static void main1(String[] args) throws InterruptedException {
        arr = new int[1000_0000];
        Random r = new Random();
        for(int i = 0;i < arr.length;i++) {
            arr[i] = Math.abs(r.nextInt()) % 100 + 1;
        }
        Thread t1 = new Thread(()-> {
            for(int i = 1;i < arr.length;i+=2) {
                sum1 += arr[i];
            }
        });
        Thread t2 = new Thread(()-> {
            for(int i = 0;i < arr.length;i+=2) {
                sum2 += arr[i];
            }
        });
        long startTime = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long endTime = System.currentTimeMillis();
        System.out.println(sum1 + sum2);
        System.out.println(endTime - startTime);

    }

    public static void main2(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("1");
            }
        });
        t.start();
        System.out.println("2");
    }

    public static int count;
    public static void main3(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(()-> {
            for(int i = 0;i < 10000;i++) {
                synchronized (locker) {
                    count++;
                }
            }
        });
        Thread t2 = new Thread(()-> {
            for(int i = 0;i < 10000;i++) {
                synchronized (locker) {
                    count++;
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(count);
    }

    public static void main4(String[] args) {
        Thread t1 = new Thread(()-> {
            System.out.println("a");
        });
        Thread t2 = new Thread(()-> {
            System.out.println("b");
        });
        Thread t3 = new Thread(()-> {
            System.out.println("c");
        });
        t1.start();
        t2.start();
        t3.start();

    }

    public static int flag = 0;
    public static void main5(String[] args) {
        Thread t1 = new Thread(()-> {
            while(flag == 0) {

            }
            System.out.println("t1 线程结束");
        });
        Thread t2 = new Thread(()-> {
            System.out.println("请输入 flag 的值：");
            Scanner in = new Scanner(System.in);
            flag = in.nextInt();
        });
        t1.start();
        t2.start();
    }

    public int wiggleMaxLength(int[] nums) {
        int n = nums.length;
        int[] f = new int[n]; //i 与前一个数差值为正
        int[] g = new int[n]; //差值为负
        for(int i = 0;i < n;i++) {
            f[i] = g[i] = 1;
        }
        int max = 1;
        for(int i = 0;i < n;i++) {
            for(int j = 0;j < i;j++) {
                if(nums[i] - nums[j] > 0) {
                    f[i] = Math.max(g[j]+1,f[i]);
                    g[i] = 1;
                } else if(nums[i] - nums[j] < 0) {
                    g[i] = Math.max(f[j]+1,g[i]);
                    f[i] = 1;
                }
                max = Math.max(f[i],g[i]);
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int[] arr = {3};
        Main main = new Main();
        main.wiggleMaxLength(arr);
    }

    ////////////////////////////////////

    public static void main111(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(()-> {
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

    }
}
